package ooday03;

public class RefArrayDemo {
    public static void main(String[] args) {
       //演示数组的初始化：
        /*Dog[]dogs=new Dog[3];
        dogs[0]=new Dog("小黑",2,"黑");
        dogs[1]=new Dog("小白",2,"白");
        dogs[2]=new Dog("小灰",3,"灰");
        dogs[2].eat();
        System.out.println();

        Chick[]chicks=new Chick[2];
        chicks[0]=new Chick("小黄",1,"黄");
        chicks[1]=new Chick("小绿",2,"绿");
        System.out.println();

        Fish[]fishs=new Fish[4];
        fishs[0]=new Fish("小红",1,"红");
        fishs[1]=new Fish("大红",2,"红");
        fishs[2]=new Fish("小金",3,"金");
        fishs[3]=new Fish("大金",4,"金");

         */
        //数组元素的访问：
        Dog[]dogs=new Dog[3];
        dogs[0]=new Dog("小黑",2,"黑");
        dogs[1]=new Dog("小白",2,"白");
        dogs[2]=new Dog("小灰",3,"灰");
        for (int i=0;i< dogs.length;i++){
            dogs[i].swim();
            dogs[i].eat();
            dogs[i].drink();
            System.out.println(dogs[i].age);
        }
        System.out.println();

        Chick[]chicks=new Chick[2];
        chicks[0]=new Chick("小黄",1,"黄");
        chicks[1]=new Chick("小绿",2,"绿");
        for (int i=0;i<chicks.length;i++){
            chicks[i].layEggs();
            System.out.println(chicks[i].age);
        }
        System.out.println();

        Fish[]fishs=new Fish[4];
        fishs[0]=new Fish("小红",1,"红");
        fishs[1]=new Fish("大红",2,"红");
        fishs[2]=new Fish("小金",3,"金");
        fishs[3]=new Fish("大金",4,"金");
        for (int i=0;i< fishs.length;i++){
            fishs[i].swim();
            System.out.println(fishs[i].color);
        }
    }
}
